/*lic*/
#ifndef __BUF_DEF_H__
#define __BUF_DEF_H__
#include <stdint.h>
#include <rtthread.h>
#include "main.h"

#include "BaseDef.h"

// 定义基础内存池
extern struct rt_mempool sdram1_mp;

// 串口9 RS485-3接收信号
extern rt_sem_t rs485_3_usart_tx_sem;
extern rt_sem_t rs485_3_usart_rx_sem;
// rs495-3接收邮箱
extern struct rt_messagequeue rs485_3_usart_rx_mq;

// 配置文件结构体
typedef struct __Tag_Config_Map_Def {
	char key[32];
	char value[256];
} Config_Map_Def;

#define CONFIG_ARRAY_SIZE 10
extern const Config_Map_Def device_address[CONFIG_ARRAY_SIZE];

// 宏定义区 这里指定各个缓冲区的功能名
// 调试串口
#define debug_rx_msg_pool usart_3_rx_msq_pool
#define debug_rx_msg_buf usart_3_tx_msq_buf

// RT485-1串口
#define rs485_rx_size u2_rx_size
// 应用侧缓冲区
#define rs485_1_rx_app_buf usart_2_rx_app_buf
#define rs485_1_tx_app_buf usart_2_tx_app_buf
// 外设侧缓冲区
#define rs485_1_rx_msq_buf usart_2_rx_msq_buf
#define rs485_1_rx_msq_buf usart_2_rx_msq_buf
// 邮箱内存池
#define rs485_1_rx_msq_pool usart_2_rx_msq_pool
#define rs485_1_tx_msq_pool usart_2_tx_msq_pool

// RS485-2 串口
#define rs485_2_rx_app_buf usart_6_rx_app_buf
#define rs485_2_tx_app_buf usart_6_tx_app_buf
#define rs485_2_rx_msq_buf usart_6_rx_msq_buf
#define rs485_2_rx_msq_buf usart_6_rx_msq_buf
#define rs485_2_rx_msq_pool usart_6_rx_msq_pool
#define rs485_2_tx_msq_pool usart_6_tx_msq_pool

// RS485-3 串口
#define rs485_3_rx_app_buf usart_9_rx_app_buf
#define rs485_3_tx_app_buf usart_9_tx_app_buf
#define rs485_3_rx_msq_buf usart_9_rx_msq_buf
#define rs485_3_rx_msq_buf usart_9_rx_msq_buf
#define rs485_3_rx_msq_pool usart_9_rx_msq_pool
#define rs485_3_tx_msq_pool usart_9_tx_msq_pool

// I2C4 外部RTC 温湿度传感器
#define rtc_thw_rx_app_buf i2c_4_rx_app_buf
#define rtc_thw_tx_app_buf i2c_4_tx_app_buf
#define rtc_thw_rx_msq_buf i2c_4_rx_msq_buf
#define rtc_thw_tx_msq_buf i2c_4_tx_msq_buf
#define rtc_thw_rx_msq_pool i2c_4_rx_msq_pool
#define rtc_thw_tx_msq_pool i2c_4_tx_msq_pool

// flash区域
// 主flash

// 备用flash

// 扩展文件存储

// 串口接收计数器
extern uint32_t u1_rx_size;
extern uint32_t u2_rx_size;
extern uint32_t u6_rx_size;
extern uint32_t u9_rx_size;
// 系统状态标志位
extern uint8_t sys_status;
// mqtt客户端ID
extern char mqtt_client_id[128];



// SDRAM1 128K
// 串口处理缓冲区
extern rt_uint8_t usart_1_rx_app_buf[1024];
extern rt_uint8_t usart_1_tx_app_buf[1024];
extern rt_uint8_t usart_2_rx_app_buf[1024];
extern rt_uint8_t usart_2_tx_app_buf[1024];
extern rt_uint8_t usart_6_rx_app_buf[1024];
extern rt_uint8_t usart_6_tx_app_buf[1024];
extern rt_uint8_t usart_9_rx_app_buf[1024];
extern rt_uint8_t usart_9_tx_app_buf[1024];

// 串口邮箱缓冲区 
extern rt_uint8_t usart_1_rx_msq_pool[4096]; // 4长度内存池
extern rt_uint8_t usart_1_tx_msq_pool[4096];
extern rt_uint8_t usart_2_rx_msq_pool[4096];
extern rt_uint8_t usart_2_tx_msq_pool[4096];
extern rt_uint8_t usart_6_rx_msq_pool[4096];
extern rt_uint8_t usart_6_tx_msq_pool[4096];
extern rt_uint8_t usart_9_rx_msq_pool[4096];
extern rt_uint8_t usart_9_tx_msq_pool[4096];
// 控制台邮箱收发缓冲区
extern rt_uint8_t usart_3_rx_msq_pool[15360]; // 10长度内存池
// 控制台rx不需要邮箱。这里给别的功能用
extern I2c_Data_Task_Def eeprom_1_write_app_buf;
extern I2c_Data_Task_Def eeprom_1_read_app_buf;

// mqtt缓冲区 共计17280字节
extern rt_uint8_t mqtt_rx_msg_pool[6170]; // 5长度内存池
extern rt_uint8_t mqtt_tx_msg_pool[6170];
extern __IO rt_uint8_t mqtt_rx_msg_buf[1234];
extern __IO rt_uint8_t mqtt_tx_msg_buf[1234];
extern rt_uint8_t mqtt_rx_app_buf[1234];
extern rt_uint8_t mqtt_tx_app_buf[1234];

// 这里剩下4字节 0x20011FFC
extern __IO rt_uint32_t crc_buf;

//__attribute__((at(0x2000DC00))) rt_uint8_t usart_3_tx_msq_pool[15360];
// 控制台rx不需要邮箱。这里给别的功能用

// I2C邮箱缓冲区
extern I2c_Data_Task_Def i2c_2_rx_msq_pool[4]; // 4长度内存池
extern I2c_Data_Task_Def i2c_2_tx_msq_pool[4];
extern I2c_Data_Task_Def i2c_4_rx_msq_pool[4];
extern I2c_Data_Task_Def i2c_4_tx_msq_pool[4];
extern rt_uint8_t usb_fs_dp_msq_pool[256];
extern rt_uint8_t usb_fs_dn_msq_pool[256];
extern rt_uint8_t usb_hs_dp_msq_pool[256];
extern rt_uint8_t usb_hs_dn_msq_pool[256];

//  0x20012900 - 0x20013FFF
// 收发缓冲区
extern __IO I2c_Data_Task_Def i2c_2_rx_msq_buf; //*
extern __IO I2c_Data_Task_Def i2c_2_tx_msq_buf; //*
extern __IO I2c_Data_Task_Def i2c_4_rx_msq_buf; //*
extern __IO I2c_Data_Task_Def i2c_4_tx_msq_buf; //*
extern __IO rt_uint8_t usb_fs_dp_msq_buf[64]; //*
extern __IO rt_uint8_t usb_fs_dn_msq_buf[64]; //*
extern __IO rt_uint8_t usb_hs_dp_msq_buf[64]; //*
extern __IO rt_uint8_t usb_hs_dn_msq_buf[64]; //*
// 从0x20012A00继续
// eeprom 外设收发缓冲区
extern __IO I2c_Data_Task_Def eeprom_1_write_buf; //*
extern __IO I2c_Data_Task_Def eeprom_1_read_buf; //*
extern I2c_Data_Task_Def eeprom_1_write_pool[10]; // 10长度缓冲区
extern I2c_Data_Task_Def eeprom_1_read_pool[10];
// 从0x20013000继续

// 串口外设缓冲区 
extern __IO rt_uint8_t usart_1_rx_msq_buf[1024]; //*
extern __IO rt_uint8_t usart_1_tx_msq_buf[1024]; //*
extern __IO rt_uint8_t usart_2_rx_msq_buf[1024]; //*
extern __IO rt_uint8_t usart_2_tx_msq_buf[1024]; //*
extern __IO rt_uint8_t usart_6_rx_msq_buf[1024]; //*
extern __IO rt_uint8_t usart_6_tx_msq_buf[1024]; //*
extern __IO rt_uint8_t usart_9_rx_msq_buf[1024]; //*
extern __IO rt_uint8_t usart_9_tx_msq_buf[1024]; //*
// 控制台外设收发缓冲区
// 控制台rx不需要缓冲区。这里给别的功能用
// 应用侧缓冲区
// i2c处理缓冲区
extern I2c_Data_Task_Def i2c_2_rx_app_buf;
extern I2c_Data_Task_Def i2c_2_tx_app_buf;
extern I2c_Data_Task_Def i2c_4_rx_app_buf;
extern I2c_Data_Task_Def i2c_4_tx_app_buf;
// USB处理缓冲区
extern rt_uint8_t usb_fs_dp_app_buf[64];
extern rt_uint8_t usb_fs_dn_app_buf[64];
extern rt_uint8_t usb_hs_dp_app_buf[64];
extern rt_uint8_t usb_hs_dn_app_buf[64];
// SDIO处理缓冲区
extern rt_uint8_t sdio_1_rx_app_buf[512];
extern rt_uint8_t sdio_1_tx_app_buf[512];
//extern rt_uint8_t usart_3_rx_msq_buf[1536];
// rx不需要缓冲区。这里给别的功能用
extern __IO rt_uint8_t usart_3_tx_msq_buf[1536];
// 从0x20016C00继续
// SDIO1外设收发缓冲区
extern __IO rt_uint8_t sdio_1_rx_buf[512];//*
extern __IO rt_uint8_t sdio_1_tx_buf[512];//*
// 从0x20017000继续
extern __IO rt_uint8_t flash_1_write_buf[4096];
extern __IO rt_uint8_t flash_1_read_buf[4096];
extern __IO rt_uint8_t flash_1_cache_buf[4096];
extern __IO rt_uint8_t flash_2_write_buf[4096];
extern __IO rt_uint8_t flash_2_read_buf[4096];
extern __IO rt_uint8_t flash_2_cache_buf[4096];
extern __IO rt_uint8_t flash_3_write_buf[4096];
extern __IO rt_uint8_t flash_3_read_buf[4096];
extern __IO rt_uint8_t flash_3_cache_buf[4096];

#endif /* __BUF_DEF_H__ */

/*eof*/
